
package com.loong.loong.hik.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.loong.loong.common.core.util.R;
import com.loong.loong.hik.entity.HikCdcVideoMonitor;
import com.loong.loong.hik.mapper.HikCdcVideoMonitorMapper;
import com.loong.loong.hik.property.request.video.VideoQryCameraRequest;
import com.loong.loong.hik.property.result.video.VideoQryCameraResult;
import com.loong.loong.hik.property.urls.face.HikFaceUrl;
import com.loong.loong.hik.service.HikCdcVideoMonitorService;
import com.loong.loong.hik.service.HikVideoVService;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * 疾控视频监控
 *
 * @author jinyiang
 * @date 2023-04-26 16:13:54
 */
@Service
public class HikCdcVideoMonitorServiceImpl extends ServiceImpl<HikCdcVideoMonitorMapper, HikCdcVideoMonitor> implements HikCdcVideoMonitorService {

	@Resource
	private HikVideoVService hikVideoVService;
	/**
	 * 根据indexCode更新Url
	 * @param hikCdcVideoMonitor
	 * @return
	 */
	@Override
	public R updateUrl(HikCdcVideoMonitor hikCdcVideoMonitor) {

		if (HikFaceUrl.SWITCH.equals("Y")){
			VideoQryCameraRequest videoQryCameraRequest = new VideoQryCameraRequest();
			videoQryCameraRequest.setCameraIndexCode(hikCdcVideoMonitor.getIndexCode());
			videoQryCameraRequest.setStreamType(0);
			videoQryCameraRequest.setProtocol("rtsp");
			videoQryCameraRequest.setTransmode(1);
			videoQryCameraRequest.setExpand("streamform=rtp");
//			videoQryCameraRequest.setStreamform("ps");
			HikCdcVideoMonitor one = getOne(Wrappers.query(hikCdcVideoMonitor));
			if (one!=null){
				hikCdcVideoMonitor.setId(one.getId());
				try {
					VideoQryCameraResult videoQryCameraResult = hikVideoVService.qryCamera(videoQryCameraRequest);
					if ("0".equals(videoQryCameraResult.getCode())&&videoQryCameraResult.getData()!=null){
						hikCdcVideoMonitor.setVideoUrl(videoQryCameraResult.getData().getUrl());

						updateById(hikCdcVideoMonitor);
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		return R.ok();
	}
}
